package xyz.chenyongpeng.orderconsumerdubbo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.chenyongpeng.entity.ZsCouponCode;
import xyz.chenyongpeng.entity.ZsCouponIncludeGoods;
import xyz.chenyongpeng.service.IZsCouponCodeService;
import xyz.chenyongpeng.service.IZsCouponIncludeGoodsService;
import xyz.chenyongpeng.service.IZsCouponService;
import xyz.chenyongpeng.to.CouponTo;
import xyz.chenyongpeng.to.MyCoupons;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class CouponService {

    @Autowired
    private IZsCouponService zsCouponService;

    @Autowired
    private IZsCouponCodeService zsCouponCodeService;

    @Autowired
    private IZsCouponIncludeGoodsService zsCouponIncludeGoodsService;

    public List<ZsCouponIncludeGoods> getCouponIdByGoodsId(String goods_id){
        return zsCouponIncludeGoodsService.getAllCoupons(Arrays.asList(goods_id.split(",")));
    }

    public List<String> getAllUserCoupon(String u_id){
        return zsCouponCodeService.getUserAllCoupons(u_id);
    }

    public List<CouponTo> getListByLimit(Map<String,Object> parms){
        return zsCouponService.getListByLimit(parms);
    }

    public int countByCoupon(Map<String,Object> parms){
        return zsCouponService.countByCoupon(parms);
    }

    public boolean publish(String coupon_id,String u_id){
        ZsCouponCode zsCouponCode = new ZsCouponCode();
        zsCouponCode.setCodeId(Integer.parseInt(coupon_id));
        zsCouponCode.setUId(Integer.parseInt(u_id));
        return zsCouponCodeService.saveCoupon(zsCouponCode);
    }

    public List<MyCoupons> getMyCoupons(Map<String,Object> parms){
        return zsCouponService.getMyCoupons(parms);
    }
    public int getMyCouponsCount(Map<String,Object> parms){
        return zsCouponService.getMyCouponsCount(parms);
    }

    public List<Long> getGoodsIdByCouponId(String coupon_id){
        return zsCouponService.getGoodsIdByCouponId(coupon_id);
    }
}
